document.getElementById("begin_time") && bmCommonFun.initDateTimePicker("begin_time");
document.getElementById("end_time") && bmCommonFun.initDateTimePicker("end_time");

search_data && bmCommonFun.searchList({
    url: search_data.url,
    data: search_data.data
});

avalon.define({
    $id: "vm-edit",
    hasCheckAll: false,
    hasCheck: false,
    hasRoleList: false,
    checkItem: [],
    delRole(id) {
        // 列表单项删除
        layer.confirm('确认删除已选中的项？', {
            btn: ['取消', '删除'] //按钮
        }, () => {
            // 已取消操作
            layer.closeAll();
        }, () => {
            // 删除操作
            $handleAjax.handle({
                url: APP_ROOT + "/mapi/index.php?ctl=user_two&act=role_delete",
                type: "POST",
                data: {
                    id: id
                },
                dataType: "json",
                isTip: false,
            }).done(function(result) {

                if (result.status == 1) {
                    layer.msg(result.error || '操作成功', {
                        time: 1000
                    });
                    setTimeout(function() {
                        location.reload();
                    }, 1000);
                } else {
                    layer.msg(result.error || '操作失败');
                }

            }).fail(function(err) {
                layer.msg(err || '操作失败');
            });
        });
    },
    delChooseRole() {
        // 批量删除
        let self = this;
        if (self.checkItem.length <= 0) {
            layer.msg('请选择要删除的项');
            return false;
        }
        layer.confirm('确认删除已选中的项？', {
            btn: ['取消', '删除'] //按钮
        }, function() {
            // 已取消操作
        }, () => {
            // 删除操作
            $handleAjax.handle({
                url: APP_ROOT + "/mapi/index.php?ctl=user_two&act=role_delete",
                type: "POST",
                data: {
                    id: JSON.stringify(self.checkItem)
                },
                dataType: "json",
                isTip: false,
            }).done(function(result) {

                if (result.status == 1) {
                    layer.msg(result.error || '操作成功', {
                        time: 1000
                    });
                    setTimeout(function() {
                        location.reload();
                    }, 1000);
                } else {
                    layer.msg(result.error || '操作失败');
                }

            }).fail(function(err) {
                layer.msg(err || '操作失败');
            });
        });
    },
    checkAll(e) {
        let self = this,
            single_check = document.getElementsByClassName("single_check");
        for (var i = 0; i < single_check.length; i++) {
            if (e.target.checked) {
                single_check[i].checked = true;
                self.checkItem.push(single_check[i].value);
            } else {
                single_check[i].checked = false;
                self.checkItem.length = 0;
            }
        }
    },
    checkLicense(){
        $handleAjax.handle({
            url: APP_ROOT + "/mapi/index.php?ctl=user_two&act=role_add",
            type: "GET",
            dataType: "json",
            isTip: false,
        }).done(function(result) {

            if (result.status == 1) {
               location.href = TMPL_REAL + '/index.php?ctl=user_two&act=role_add';
            } else {
                layer.msg(result.error || '操作失败');
            }

        }).fail(function(err) {
            layer.msg(err || '操作失败');
        });
    }
});